//
//  moreSetting.m
//  HappyStore
//
//  Created by 李小辉 on 16/7/29.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "moreSetting.h"
#import "mainMyCell.h"
#import "downFile.h"
#import "ReceiveResume.h"
#import "authPersonal.h"
#import "MyMemberShipVC.h"
#import "authUser.h"//实名认证
#import "QuotesAndOrder.h"
@interface moreSetting ()
@property (strong, nonatomic) NSArray *imageAry;
@property (strong, nonatomic) NSArray *titleAry;

@end

@implementation moreSetting

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"白色背景"] forBarMetrics:UIBarMetricsDefault];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    labelTitle.font = [UIFont systemFontOfSize:19];
    labelTitle.backgroundColor = [UIColor clearColor];
    labelTitle.text = @"更多";
    labelTitle.textColor = RGB(45, 45, 45);
    labelTitle.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = labelTitle;
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"返回" highImage:@"返回"];
    self.navigationItem.leftBarButtonItem = leftItem;
    self.tabBarController.tabBar.hidden = YES;
    [self setExtraCellLineHidden:self.tableView];
    
    if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {//个人
        
        self.titleAry = @[@"投递记录",@"收到简历",@"下载目录",@"分享乐商网",@"实名认证",@"我的会员",@"在线报价",@"在线订购"];
        self.imageAry = @[@"更多-投递",@"更多-简历",@"更多-下载",@"更多-分享",@"更多-实名",@"更多-会员",@"更多-报价",@"更多-订购"];
        
    }else {//企业/政府
        
        self.titleAry = @[@"收到简历",@"下载目录",@"分享乐商网",@"实名认证",@"我的会员",@"在线报价",@"在线订购"];
        self.imageAry = @[@"更多-简历",@"更多-下载",@"更多-分享",@"更多-实名",@"更多-会员",@"更多-报价",@"更多-订购"];
    }
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}


-(void)leftBarButtonItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}
//去掉多余的表格线
- (void)setExtraCellLineHidden:(UITableView *)tableView{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    [tableView tableViewDisplayWitMsg:@"没有查询到相对应的数据" ifNecessaryForRowCount:self.titleAry.count];
    return self.titleAry.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 53;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    mainMyCell *cell = [[mainMyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mainCell"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.imageView.image = [UIImage imageNamed: self.imageAry[indexPath.row]];
    cell.textLabel.text = self.titleAry[indexPath.row];
    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {
        if (indexPath.row == 0) {//投递记录
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
            ReceiveResume *receiveResumeVC = [storyboard instantiateViewControllerWithIdentifier:@"ReceiveResume"];
            receiveResumeVC.mainType = 1;
            [self.navigationController pushViewController:receiveResumeVC animated:YES];
            
        }else if(indexPath.row == 1){//收到的简历
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
            ReceiveResume *receiveResumeVC = [storyboard instantiateViewControllerWithIdentifier:@"ReceiveResume"];
            receiveResumeVC.mainType = 4;
            [self.navigationController pushViewController:receiveResumeVC animated:YES];
        }else if(indexPath.row == 2){//下载目录
            downFile *downfileVC = [[downFile alloc] init];
            [self.navigationController pushViewController:downfileVC animated:YES];
        }else if(indexPath.row == 3){//分享
            [self shareClick];
        }else if(indexPath.row == 4){
            
            if ([self.authStateString integerValue] == 2) {
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"您已是认证用户" message:nil preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                [alert addAction:alertAction];
                [self presentViewController:alert animated:YES completion:nil];
            }else{
                authPersonal *authPersonalVC = [[authPersonal alloc] init];
                [self.navigationController pushViewController:authPersonalVC animated:YES];
            }
        }else if(indexPath.row == 5){//我的会员
            MyMemberShipVC *menmberVC = [[MyMemberShipVC alloc] init];
            menmberVC.levelovertime = self.levelovertime;
            [self.navigationController pushViewController:menmberVC animated:YES];
        }else if(indexPath.row == 6){//在线报价
            QuotesAndOrder *quotesAndOrderVC = [[QuotesAndOrder alloc] init];
            quotesAndOrderVC.typeStr = @"在线报价";
            [self.navigationController pushViewController:quotesAndOrderVC animated:YES];
        }else{//在线订购
            QuotesAndOrder *quotesAndOrderVC = [[QuotesAndOrder alloc] init];
            quotesAndOrderVC.typeStr = @"在线订购";
            [self.navigationController pushViewController:quotesAndOrderVC animated:YES];
        }
    }else{//企业和政府
        if (indexPath.row == 0) {//收到的简历
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
            ReceiveResume *receiveResumeVC = [storyboard instantiateViewControllerWithIdentifier:@"ReceiveResume"];
            receiveResumeVC.mainType = 4;
            [self.navigationController pushViewController:receiveResumeVC animated:YES];
        }else if(indexPath.row == 1){//下载目录
            downFile *downfileVC = [[downFile alloc] init];
            [self.navigationController pushViewController:downfileVC animated:YES];
        }else if(indexPath.row == 2){//分享
            [self shareClick];
        }else if(indexPath.row == 3){//认证
            
            if ([self.authStateString integerValue] == 2) {
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"贵方已是认证用户" message:nil preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                [alert addAction:alertAction];
                [self presentViewController:alert animated:YES completion:nil];
            }else{//未认证
                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
                authUser *authVC  = [storyboard instantiateViewControllerWithIdentifier:@"myauthuser"];
                authVC.strHeaderURl = [USER_DEFAULTS objectForKey:@"headPhoto"];
                if ([USER_DEFAULTS objectForKey:@"userName"] == [NSNull null] || [[USER_DEFAULTS objectForKey:@"userName"] isEqualToString:@"null"]) {
                    authVC.strUserName = [USER_DEFAULTS objectForKey:@"account"];
                }else {
                    authVC.strUserName = [USER_DEFAULTS objectForKey:@"userName"];
                }
                [self.navigationController pushViewController:authVC animated:YES];
                
            }
        }else if(indexPath.row == 4){//我的会员
            MyMemberShipVC *menmberVC = [[MyMemberShipVC alloc] init];
            menmberVC.levelovertime = self.levelovertime;
            [self.navigationController pushViewController:menmberVC animated:YES];
        }else if(indexPath.row == 5){//在线报价
            QuotesAndOrder *quotesAndOrderVC = [[QuotesAndOrder alloc] init];
            quotesAndOrderVC.typeStr = @"在线报价";
            [self.navigationController pushViewController:quotesAndOrderVC animated:YES];
        }else{//在线订购
            QuotesAndOrder *quotesAndOrderVC = [[QuotesAndOrder alloc] init];
            quotesAndOrderVC.typeStr = @"在线订购";
            [self.navigationController pushViewController:quotesAndOrderVC animated:YES];
        }
    }

}



#pragma mark - 解决表格线不到左边界
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}


- (void)viewDidLayoutSubviews{
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
}







//分享
- (void)shareClick{
    
    [ShareMsg shareMsgBOOLType:YES titleStr:nil contentStr:nil urlStr:nil imageAry:nil];
}

@end
